package com.yhq.spring.i18n.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Locale;

/**
 * @author hqyin
 * @date 2023/4/21 11:28 上午
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private MessageSource messageSource;

    @GetMapping("/getName")
    public String hello(@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage) {
        return messageSource.getMessage("user.名字",null, new Locale(acceptLanguage));
    }
}
